package lzy.mapper;

import lzy.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface UserMapper {
    
    @Select("SELECT * FROM user WHERE username = #{username}")
    User findByUsername(String username);
    
    @Insert("INSERT INTO user (username, password, real_name, phone, email, role, enabled) " +
            "VALUES (#{username}, #{password}, #{realName}, #{phone}, #{email}, #{role}, #{enabled})")
    void insert(User user);

    @Update("UPDATE user SET password = #{newPassword}, update_time = NOW() WHERE id = #{id}")
    int updatePassword(@Param("id") Long id, @Param("newPassword") String newPassword);

    java.util.List<User> findByRole(String role);
    int countAll();
    void addUser(User user);
    java.util.List<User> findAll();
    void deleteById(Long id);
} 